<template>
    <div>
      <form action="javascript:;" method="get" class="loginRegisterFrom">
        <section>
          <label class="label1">
            <p>{{$t("loginRegistration.login.username")}}</p>
            <input type="text" v-model="userName" placeholder=" ">
            <div class="border"></div>
          </label>
          <label class="label4">
            <p>{{$t("loginRegistration.login.password")}}</p>
            <input type="password" v-model="password" placeholder=" ">
            <div class="border"></div>
          </label>
          <button type="submit" id="submit" @click="tips">
            {{$t("loginRegistration.login.buttonName")}}
          </button>
        </section>
      </form>
    </div>
</template>

<script>
    export default {
        name: "Login",
        data(){
            return{
                baseURL:'http://localhost:8081/loginReg/login/',
                userName:'',
                password:''
            }
        },
        mounted(){
            this.$emit("component","login")
            let registration = this.$route.query.res
            // let registrationResult = typeof registration +''
            if(registration == "true01"){
                this.$message.success(this.$t("loginRegistration.login.registrationSuccess"))
            }else if (registration == "true02"){
                this.$message.success(this.$t("loginRegistration.login.findPasswordSuccess"))
            }else if(registration == "true03"){
                this.$message.warning(this.$t("loginRegistration.login.loginOrRegistration"))
            }
        },
        methods:{
            tips(){
                if (this.userName=='' || this.password==''){
                    this.$message.warning(this.$t("loginRegistration.login.usernameOrPasswordIllegal"))
                }else {
                    let urlSub = this.userName+'/'+this.password
                    this.axios.post(this.baseURL+urlSub).then((res)=>{
                        if (res.data == true){
                            // 登录验证通过,跳转到首页
                            this.$router.push('/homepage')
                        } else if (res.data == false){
                            //登录验证不通过
                            this.$message.error(this.$t("loginRegistration.login.usernameOrPasswordError"))
                        } else if (res.data == "noLogin") {
                            this.warningOpt(this.$t("loginRegistration.login.accountsUnusual"))
                        } else {
                            this.$message.error(this.$t("loginRegistration.login.serviceUnusual"))
                        }
                    }).catch(
                        exception=>{
                            console.log(exception)
                        }
                    )
                }
            },

            successOpt(message) {
                this.$notify({
                    title: this.$t("notify.success"),
                    message: message,
                    type: 'success',
                })
            },
            warningOpt(message) {
                this.$notify.warning({
                    title: this.$t("notify.warning"),
                    message: message
                });
            }
        }
    }
</script>

<style scoped>
  .loginRegisterFrom section label {
    display: block;
    margin-bottom: 15px;
    position: relative
  }
  .loginRegisterFrom section label p {
    color: rgb(58, 58, 58);
    margin: 0 0 10px 0;
    font-weight: 600;
    font-size: 12px;
    opacity: .8;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
  }

  .loginRegisterFrom section label input {
    width: 100%;
    display: block;
    border: 0;
    background: transparent;
    color: rgb(58, 58, 58);
    border-bottom: 1px solid rgba(0, 0, 0, 0.2);
    padding: 0 0 10px;
    box-sizing: border-box;
    font-weight: 600;

  }

  .loginRegisterFrom section label input:focus~.border {
    transform: scale(1, 1);
  }

  .loginRegisterFrom section label .border {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: rgb(58, 58, 58);
    transform: scale(0, 1);
    transition: .2s ease;
  }

  .loginRegisterFrom section label:last-child {
    margin-bottom: 0;
  }
  .label1,
  .label4{
    height: 48px;
    transition: 0.2s;
    overflow: hidden;
    /*background-color: tomato;*/
  }
  .loginRegisterFrom section button {
    background: #05a090;
    border: 0;
    width: 100%;
    padding: 10px 0;
    font-weight: 600;
    border-radius: 3px;
    color: rgb(236, 236, 236);
    cursor: pointer;
    letter-spacing: 2px;
    margin-top: 15px;
  }

  .loginRegisterFrom section button:hover {
    background: #009788;
    color: rgb(255, 255, 255);
  }
</style>
